home *** CD-ROM | disk | FTP | other *** search
INI File | 1985-04-07 | 6.6 KB | 208 lines |
- [74036,3110]
- ARGLIB.DOC 16-Mar-85 6400 76
-
- Keywords: PORTABLE FILE ARGUMENTS CPM-80 CPM-86 MS-DOS TURBO
- PASCALMT+ BSD UNIX PASCAL
-
- PAGE 1
-
-
-
- ArgLib - A Portable Pascal File Argument Library
-
- 15 March 1985
-
- Willett Kempton
-
-
-
-
- What ArgLib Does
- ----------------
-
- Arglib provides a portable means of reading file arguments from
- the operating system command line into a Pascal program. It also
- allows assignment of a name to a file variable and detection of empty
- files. ArgLib became necessary because almost every company's version
- of Pascal has implemented these functions in a different way. By
- calling ArgLib, rather than writing system-specific code in each
- program, software can be more easily moved across compilers, operating
- systems and computers.
-
- ArgLib is currently available for:
-
- 1. Turbo Pascal, CP/M-80, CP/M-86, MS-DOS
- 2. Pascal/MT+, Pascal/MT+86
- 3. Berkeley UNIX Pascal, pi, pc
-
- Specifics on these implementations follow:
-
- 1. ArgLib.pas: Turbo pascal. Tested with Turbo v 1 and v 2, on
- CP/M-80, CP/M-86, and MS-DOS on a DEC Rainbow. Requires a
- minor modification (marked in the code) to switch among these
- operating systems. Also, a bug in 8-bit Turbo (v1, v2)
- truncates any command line arguments past 31 characters.
-
- 2. ArgLibMT.pas: Pascal/MT+86 and Pascal/MT+. Tested with MT+86
- V 3.1. Note that in the MT+ version, "argcount" must be
- called prior to "argv". This is the typical calling sequence
- anyway, but is REQUIRED under MT+ systems.
-
- 3. ArgLibUX.pas: Berkeley UNIX Pascal. Tested on Pascal version
- 3.0, using both the pi interpreter and the pc compiler on a
- VAX 11/750 running BSD 4.1.
-
-
-
- Procedures avaliable
- --------------------
-
- argcount: Argument count. Function returning an integer count of
- how many file arguments were given on the command line.
-
- argv(count,name): Argument Value. Procedure setting the variable
- "name" to argument number "count" from the command line.
-
-
-
-
-
-
-
-
-
- ArgLib -- Portable file argument library PAGE 2
-
-
-
- resetOK(file,name): Assign, reset, and check. Assign the file
- variable "file" to read from the external file or device named "name".
- If the external file is nonexistant or empty, return false. Otherwise
- return true.
-
- For example, suppose that the user calls program "cp" with two
- files:
-
- A>CP FILEA FILEB
-
- argcount --> returns the value 2
- argv(1,name) --> sets "name" to 'FILEA '
- argv(2,name) --> sets "name" to 'FILEB '
- resetOK(f,name) --> resets f for reading from "name";
- if nonempty, return TRUE
-
- Note that under UNIX, argv(0,name) would set "name" to 'CP', but
- in the micro version it sets "name" to blank.
-
- Most pascal systems will require ArgLib to be included after the
- last variable of the main program and before the first procedure.
- After the include, the following symbols are available.
-
- Symbols available to calling program
-
- const
- MaxArgStrLen = 16; (* max chars per argument; VARIES WITH OS! *)
- type
- ArgStrType = packed array [1..MaxArgStrLen] of char;
-
- procedure argv(argn : integer; var name : ArgStrType);
-
- function argcount : integer;
-
- function resetOK (var f: text; name: ArgStrType) : boolean;
-
- Design tradeoffs were as follows. Execution speed was sacrificed
- for compact code, since these routines will typically only be called
- once. Standard Pascal (ISO standard) was used whenever possible (no
- 'string', etc.). (Berkeley UNIX Pascal provides no string type.)
-
-
- Testing ArgLib
- --------------
-
- A test program is provided with ArgLib. It is called ArgTest.pas
- and it includes ArgLib into its source. The following is a session
- using argtest on CP/M:
-
-
- F>dir
- F: SMALL : EMPTY : ARGTEST.CMD
-
- F>type empty
-
-
-
-
-
-
-
-
-
- ArgLib -- Portable file argument library PAGE 3
-
-
-
- F>type small
- this is a small file
-
- F>type nothing
- NO FILE
- F>argtest empty small nothing
- file arguments=3
- 0= empty
- 1= EMPTY empty
- 2= SMALL exists
- 3= NOTHING empty
-
- F>
-
- Note that both the empty and the nonexistant files are detected.
-
-
- Hints for Portable Code
- -----------------------
-
- Some of the programs you write will only be used a few times, or
- by their nature, will only be used on one system. These need not be
- portable. Other programs will retain their value over a period of
- years. During those years, you are likely to use different computers,
- and almost certain to use several different compilers. To preserve
- your software-writing investment, you want to be able to transfer your
- programs without having to re-write them for each system. Programs
- which allow easy transfer are considered "portable".
-
- For those programs which you want to be portable, do not use the
- compiler manufacturer's manual to guide your writing. Use a manual on
- "Standard Pascal", which is a subset of most commercial Pascals. The
- Standard is defined by ISO, the International Standards Organization,
- and by ANSI, the American member of ISO. The defining ISO document
- (ISO dp7185, December 1980) is precise but difficult to read. Two
- readable descriptions of Standard Pascal are available. One is
- "Standard Pascal, User Reference Manual", by Doug Cooper, (1983, W.
- W. Norton & Company). The other is the THIRD edition of "Pascal User
- Manual and Report", by Jensen and Wirth (1984, Springer Verlag).
- Either is preferable to the second edition of Jensen & Wirth (1974),
- which is less readable and partially inconsistent with the final ISO
- standard.
-
- Sometimes, system dependent features will be necessary, for
- example in getting file names from the operating system command line.
- When they are needed, they can be localized in a few routines which
- can be called in a standard way. Then to change all your software for
- a new system, you need only change a few routines. ArgLib is an
- example of this strategy.
-
-
-
-
-
-
-
-
- PORTABLE FILE ARGUMENTS CPM-80 CPM-86 MS-DOS TURBO PASCALMT+ BSD UNIX
- These routines allow Pascal programs to get arguments (e.g. files,
- options) from the command line. Works in all Turbo systems, with
- a one -line change (marked in comments). Versions are also available
- for Pascal/MT+ and BSD UNIX pascal (request upload).
-
-